/*     */ package com.zimbra.cs.mailclient.imap;
/*     */ 
/*     */ import java.io.IOException;
/*     */ import java.text.SimpleDateFormat;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Date;
/*     */ import java.util.Iterator;
/*     */ import java.util.List;
/*     */ import java.util.Locale;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public final class MessageData
/*     */ {
/*     */   private long msgno;
/*     */   private Flags flags;
/*     */   private Envelope envelope;
/*     */   private Date internalDate;
/*     */   private ImapData rfc822Header;
/*     */   private ImapData rfc822Text;
/*  54 */   private long rfc822Size = -1L;
/*     */   private BodyStructure bodyStructure;
/*     */   private List<Body> bodySections;
/*  57 */   private long uid = -1L;
/*     */   
/*  59 */   private static final SimpleDateFormat INTERNALDATE_FORMAT = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss Z", Locale.US);
/*     */   
/*     */   public static MessageData read(ImapInputStream is, long msgno) throws IOException
/*     */   {
/*  63 */     MessageData md = new MessageData();
/*  64 */     md.msgno = msgno;
/*  65 */     md.read(is);
/*  66 */     return md;
/*     */   }
/*     */   
/*     */   private void read(ImapInputStream is)
/*     */     throws IOException
/*     */   {
/*  72 */     is.skipSpaces();
/*  73 */     is.skipChar('(');
/*  74 */     is.skipSpaces();
/*  75 */     while (!is.match(')')) {
/*  76 */       readAttribute(is);
/*  77 */       is.skipSpaces();
/*     */     }
/*     */   }
/*     */   
/*     */   private void readAttribute(ImapInputStream is) throws IOException
/*     */   {
/*  83 */     String s = is.readChars(Chars.FETCH_CHARS);
/*  84 */     if (s.length() == 0) {
/*  85 */       throw new com.zimbra.cs.mailclient.ParseException("Zero-length attribute");
/*     */     }
/*  87 */     Atom attr = new Atom(s);
/*  88 */     CAtom cattr = attr.getCAtom();
/*  89 */     if ((cattr == CAtom.BODY) && (is.peek() == 91)) {
/*  90 */       if (this.bodySections == null) {
/*  91 */         this.bodySections = new ArrayList();
/*     */       }
/*  93 */       this.bodySections.add(Body.read(is));
/*  94 */       return;
/*     */     }
/*  96 */     is.skipSpaces();
/*  97 */     switch (attr.getCAtom()) {
/*     */     case FLAGS: 
/*  99 */       this.flags = Flags.read(is);
/* 100 */       break;
/*     */     case ENVELOPE: 
/* 102 */       this.envelope = Envelope.read(is);
/* 103 */       break;
/*     */     case INTERNALDATE: 
/* 105 */       this.internalDate = readInternalDate(is);
/* 106 */       break;
/*     */     case RFC822_HEADER: 
/* 108 */       this.rfc822Header = is.readNStringData();
/* 109 */       break;
/*     */     case RFC822_TEXT: 
/* 111 */       this.rfc822Text = is.readNStringData();
/* 112 */       break;
/*     */     case RFC822_SIZE: 
/* 114 */       this.rfc822Size = is.readNumber();
/* 115 */       break;
/*     */     case BODYSTRUCTURE: 
/* 117 */       this.bodyStructure = BodyStructure.read(is, true);
/* 118 */       break;
/*     */     case BODY: 
/* 120 */       this.bodyStructure = BodyStructure.read(is, false);
/* 121 */       break;
/*     */     case UID: 
/* 123 */       this.uid = is.readNZNumber();
/* 124 */       break;
/*     */     default: 
/* 126 */       throw new com.zimbra.cs.mailclient.ParseException("Invalid message data attribute: " + attr);
/*     */     }
/*     */   }
/*     */   
/*     */   private static Date readInternalDate(ImapInputStream is) throws IOException {
/* 131 */     String s = is.readQuoted().toString().trim();
/* 132 */     if (s.length() == 0)
/*     */     {
/*     */ 
/*     */ 
/* 136 */       return null;
/*     */     }
/* 138 */     synchronized (INTERNALDATE_FORMAT) {
/*     */       try {
/* 140 */         return INTERNALDATE_FORMAT.parse(s);
/*     */       } catch (java.text.ParseException e) {
/* 142 */         throw new com.zimbra.cs.mailclient.ParseException("Invalid INTERNALDATE value: " + s);
/*     */       }
/*     */     }
/*     */   }
/*     */   
/* 147 */   public long getMsgno() { return this.msgno; }
/* 148 */   public Flags getFlags() { return this.flags; }
/* 149 */   public Envelope getEnvelope() { return this.envelope; }
/* 150 */   public Date getInternalDate() { return this.internalDate; }
/* 151 */   public ImapData getRfc822Header() { return this.rfc822Header; }
/* 152 */   public ImapData getRfc822Text() { return this.rfc822Text; }
/* 153 */   public long getRfc822Size() { return this.rfc822Size; }
/* 154 */   public BodyStructure getBodyStructure() { return this.bodyStructure; }
/* 155 */   public long getUid() { return this.uid; }
/*     */   
/*     */   public Body[] getBodySections() {
/* 158 */     return this.bodySections != null ? (Body[])this.bodySections.toArray(new Body[this.bodySections.size()]) : null;
/*     */   }
/*     */   
/*     */   public void addFields(MessageData md)
/*     */   {
/* 163 */     if (md.flags != null) this.flags = md.flags;
/* 164 */     if (md.envelope != null) this.envelope = md.envelope;
/* 165 */     if (md.internalDate != null) this.internalDate = md.internalDate;
/* 166 */     if (md.rfc822Header != null) this.rfc822Header = md.rfc822Header;
/* 167 */     if (md.rfc822Text != null) this.rfc822Text = md.rfc822Text;
/* 168 */     if (md.rfc822Size != -1L) this.rfc822Size = md.rfc822Size;
/* 169 */     if (md.bodyStructure != null) this.bodyStructure = md.bodyStructure;
/* 170 */     if (md.bodySections != null) this.bodySections = md.bodySections;
/* 171 */     if (md.uid != -1L) this.uid = md.uid;
/*     */   }
/*     */   
/*     */   public void dispose() {
/* 175 */     if (this.rfc822Header != null) this.rfc822Header.dispose();
/* 176 */     if (this.rfc822Text != null) this.rfc822Text.dispose();
/* 177 */     if (this.bodySections != null) { Body body;
/* 178 */       for (Iterator i$ = this.bodySections.iterator(); i$.hasNext(); body.dispose()) body = (Body)i$.next();
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/mailclient/imap/MessageData.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */